package com.itheima.goods.controller;

import com.itheima.goods.pojo.Spec;
import com.itheima.goods.service.SpecService;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/spec")
public class SpecController {
    @Autowired
    private SpecService specService;

    @GetMapping
    public Result findAll() {
        return specService.findAll();
    }

    @PostMapping
    public Result add(@RequestBody Spec spec) {
        return specService.add(spec);
    }

/*    @GetMapping("/findPage")
    public PageResult<Spec> findPage(
            @RequestParam("currentPage") Integer currentPage,
            @RequestParam("pageSize") Integer pageSize,
            @RequestParam("queryString") String queryString) {
        return specService.findPage(currentPage, pageSize, queryString);
    }*/

    @GetMapping("{id}")
    public Result findById(@PathVariable("id") Integer id) {
        return specService.findById(id);
    }

    @PutMapping("{id}")
    public Result update(@PathVariable("id") Integer id, @RequestBody Spec spec) {
        return specService.updateSpec(id,spec);
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") Integer id) {
        return specService.deleteSpec(id);
    }

    @GetMapping("/search/{page}/{size}")
    public Result findPage(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        return specService.search(page, size);
    }

    @PostMapping("/search/{page}/{size}")
    public Result findPage(@PathVariable("page") Integer page, @PathVariable("size") Integer size, @RequestBody Object searchMap) {
        return specService.searchMap(page, size,searchMap);
    }

}

